import request from "@/utils/request";

export interface DailyMenuQuery extends PageQuery {
  page?: number;
  limit?: number;
  shop_id?: number;
  stype?: any;
}

export interface DailyMenuDetail {
  id: number;
  type: number;
  date: Date;
  shop_title: string;
  start_time: Date;
  end_time: Date;
  expire_start_date: Date;
  expire_end_date: Date;
  order_start_time: string;
  order_end_time: string;
  deliver_time: string;
  status: number;
}

export interface DailyMenuProduct {
  id: number;
  price: number;
  menu_id: number;
  thumb: string;
  title: string;
  products: any;
}

export interface DailyMenuProductCategory {
  id: number;
  title: string;
  products: any;
  checkAll: boolean;
}

export interface DailyMenuForm {
  id?: number;
  type?: number;
  date?: any;
  shop_id?: number;
  start_time?: string;
  end_time?: string;
  menu_type?: number;
  expire_date?: string;
  order_start_time?: string;
  order_end_time?: string;
  deliver_time?: string;
  hide?: boolean;
  status?: number;
  is_can_order?: number;
  productIds?: any;
}

const baseUri = "/mv1/api/daily-menu";

export function getDailyMenuList(query: DailyMenuQuery) {
  return request({
    url: baseUri + "/",
    method: "get",
    params: query,
  });
}

export function getDailyMenuDetail(id: number) {
  return request({
    url: baseUri + "/detail/" + id,
    method: "get",
  });
}

export function getMenuProductsOptions(id: number) {
  return request({
    url: baseUri + "/product-options/" + id,
    method: "get",
    // params: {id},
  });
}

export function geDailyMenutOptions(data: any) {
  return request({
    url: baseUri + "/options",
    method: "get",
    params: data,
  });
}

export function getMenuProducts(id: number) {
  return request({
    url: baseUri + "/products/" + id,
    method: "get",
    // params: {id},
  });
}

export function createDailyMenu(data: DailyMenuForm) {
  return request({
    url: baseUri + "/edit",
    method: "post",
    data: data,
  });
}

export function sortDailyMenu(id: number, productIds: Array<number>) {
  return request({
    url: baseUri + "/sort",
    method: "post",
    data: {
      productIds: productIds,
      id: id,
    },
  });
}

export function updateDailyMenu(id: number, data: DailyMenuForm) {
  return request({
    url: baseUri + "/edit/" + id,
    method: "put",
    data: data,
  });
}

export function addDailyMenuProducts(id: number, data: DailyMenuForm) {
  return request({
    url: baseUri + "/products/" + id,
    method: "post",
    data: data,
  });
}

/**
 * 复制
 * @param id
 */
export function copyDailyMenu(id: number) {
  return request({
    url: baseUri + "/copy/" + id,
    method: "post",
  });
}

export function deleteDailyMenu(id: number) {
  return request({
    url: baseUri + "/" + id,
    method: "delete",
  });
}

export function deleteProduct(id: number) {
  return request({
    url: baseUri + "/product/" + id,
    method: "delete",
  });
}
